package com.zkzx.wlhy.adaptor.controller.company;

import com.zkzx.common.company.command.CompanyCommand;
import com.zkzx.common.company.model.CompanyVO;
import com.zkzx.wlhy.adaptor.clinet.company.CompanyClient;
import com.zkzx.wlhy.adaptor.service.company.CompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 北京中科智兴物联科技有限公司 @版权所有
 *
 * @Author: zhaoyihe@zkraising.com
 * @Date: 2021/05/19/18:58
 * @Description:
 */
@RestController
@Validated
@Api( tags="企业接口")
@RequestMapping(value = "/companies")
public class CompanyController{

    @Autowired
    private CompanyClient companyClient;

     @Autowired
     private CompanyService companyService;

    @GetMapping("/{id}")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "查询是否存在该企业", notes = "查询是否存在该企业")
    public CompanyCommand getCompany(@PathVariable("id") Integer id, @RequestParam("name") String name, @RequestParam("code") String code){

        return companyService.getCompany(id,name,code);
    }

    @PostMapping("/{id}")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "添加企业", notes = "添加企业")
    public CompanyCommand add(@PathVariable("id") Integer id,@RequestBody @Valid CompanyVO companyVO) {
         //提交完，改状态，更新第三方企业id
        return companyService.add(id,companyVO);
    }


    @GetMapping("/{id}/status")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "查询添加企业审核状态", notes = "查询添加企业审核状态")
    public CompanyCommand getStatus(@PathVariable("id") Integer id,@RequestParam("three_id") String threeId){
        return companyService.getStatus(id, threeId);

    }

    @PostMapping("/{id}/contract")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "平台与企业的合同", notes = "平台与企业的合同")
    public CompanyCommand getContract(@PathVariable("id") Integer id, @RequestBody @Valid CompanyVO companyVO) {
        return companyService.getContract(id, companyVO);
    }
}
